package practise.alogrithm.hundredInterviewQuestions;

import java.util.ArrayList;
import java.util.List;

/**
 * get two numbers from a sorted array, the sum of the numbers should be as input.
 */
public class GetTwoNumberForSum {
    public static List<List<Integer>> getTwoNumberForSum(int[] numbers,int sum){
        int endIndex=numbers.length-1;
        int startIndex = 0;
        List<List<Integer>> result = new ArrayList<>();
        while(startIndex<endIndex){
            int tempSum = numbers[startIndex]+numbers[endIndex];
            if(tempSum==sum){
                List<Integer> number = new ArrayList<>();
                number.add(numbers[startIndex]);
                number.add(numbers[endIndex]);
                result.add(number);
                startIndex++;
                endIndex--;
            }
            if(tempSum<sum){
                startIndex++;
            }
            if(tempSum>sum){
                endIndex--;
            }
        }
        return result;
    }

    public static void main(String[] args){
        System.out.println("result:"+getTwoNumberForSum(new int[]{1,2,3,4,5,6,7,8,9},10));
    }
}
